package com.campus.campus.controller;

import com.campus.campus.job.dto.LossRecordDTO;
import com.campus.campus.job.entity.LossRecord;
import com.campus.campus.job.entity.TransactionDetail;
import com.campus.campus.job.vo.CampusCardsInfoVO;
import com.campus.campus.job.vo.TransactionDetailVO;
import com.campus.campus.service.ICampusCardsService;
import com.campus.common.result.Result;

import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MWB
 */
@RestController
@RequestMapping("/campusCard")
@Tag(name = "校园卡服务")
public class CampusCardController {

    @Autowired
    private ICampusCardsService campusCardsService;

    @ApiOperation(value = "查询校园卡信息")
    @GetMapping()
    public Result<CampusCardsInfoVO> getCampusCardInfo() {

        CampusCardsInfoVO vo = campusCardsService.getCampusCardInfo();
        return Result.success(vo);
    }

    @ApiOperation(value = "查询余额及交易记录")
    @GetMapping("/trade")
    public Result<List<TransactionDetailVO>> getTransactionRecord() {

        List<TransactionDetailVO> list = campusCardsService.getTransactionRecord();
        return Result.success(list);
    }

    @ApiOperation(value = "校园卡挂失")
    @PostMapping("/loss")
    public Result<Void> lossCard(@RequestBody LossRecordDTO lossRecordDTO) {

        campusCardsService.lossCard(lossRecordDTO);
        return Result.success();
    }

    @Operation(summary = "获取校园卡余额")
    @GetMapping("/getBalance")
    public Result getBalanceFun() {
        return campusCardsService.getBalance();
    }

}
